home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / c / amigacc68k.lha / cc68k / cmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-02  |  2.8 KB  |  118 lines

  1. #include        "stdio.h"
  2. #include        "string.h"
  3. #include        "c.h"
  4. #include        "expr.h"
  5. #include        "gen.h"
  6. #include        "cglbdec.h"
  7.  
  8. /*
  9.  *    68000 C compiler
  10.  *
  11.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  12.  *  all commercial rights reserved.
  13.  *
  14.  *    This compiler is intended as an instructive tool for personal use. Any
  15.  *    use for profit without the written consent of the author is prohibited.
  16.  *
  17.  *    This compiler may be distributed freely for non-commercial use as long
  18.  *    as this notice stays intact. Please forward any enhancements or question
  19. s
  20.  *    to:
  21.  *
  22.  *        Matthew Brandt
  23.  *        Box 920337
  24.  *        Norcross, Ga 30092
  25.  */
  26.  
  27. __stdargs void makename(char *s,char *e);
  28.  
  29. char            infile[20],
  30.                 listfile[20],
  31.                 outfile[20];
  32. extern TABLE    tagtable;
  33. int        mainflag;
  34. extern int      total_errors;
  35.  
  36.  main(argc,argv)
  37. int     argc;
  38. char    **argv;
  39. {
  40.         while(--argc) {
  41.                 if( **++argv == '-')
  42.                         options();
  43.                 else if( openfiles(*argv)) {
  44.                         lineno = 0;
  45.                         initsym();
  46.                         getch();
  47.                         getsym();
  48.                         compile();
  49.                         summary();
  50.                         release_global();
  51.                         closefiles();
  52.                         }
  53.                 }
  54. }
  55.  
  56. int    options()
  57. {
  58.   return 0;
  59. }
  60.  
  61. int     openfiles(s)
  62. char    *s;
  63. {
  64. /*        int     ofl; */
  65.  
  66.     strcpy(infile,s);
  67.         strcpy(listfile,s);
  68.         strcpy(outfile,s);
  69.         makename(listfile,".lis");
  70.     makename(outfile,".s");
  71.         if( (input = fopen(infile,"r")) == 0) {
  72.                 printf(" cant open %s\n",infile);
  73.                 return 0;
  74.                 }
  75. /*        ofl = creat(outfile,0);
  76.         if( ofl < 0 )
  77.                 {
  78.                 printf(" cant create %s\n",outfile);
  79.                 fclose(input);
  80.                 return 0;
  81.         }
  82. */
  83.     if( (output = fopen(outfile,"w")) == 0) {
  84.                 printf(" cant open %s\n",outfile);
  85.                 fclose(input);
  86.                 return 0;
  87.                 }
  88.         if( (list = fopen(listfile,"w")) == 0) {
  89.                 printf(" cant open %s\n",listfile);
  90.                 fclose(input);
  91.                 fclose(output);
  92.                 return 0;
  93.                 }
  94.         return 1;
  95. }
  96.  
  97. void makename(s,e)
  98. char    *s, *e;
  99. {       while(*s != 0 && *s != '.')
  100.                 ++s;
  101.         while(*s++ = *e++);
  102. }
  103.  
  104.  summary()
  105. {       printf("\n -- %d errors found.",total_errors);
  106.         fprintf(list,"\f\n *** global scope symbol table ***\n\n");
  107.         list_table(&gsyms,0);
  108.         fprintf(list,"\n *** structures and unions ***\n\n");
  109.         list_table(&tagtable,0);
  110. }
  111.  
  112.  closefiles()
  113. {       fclose(input);
  114.         fprintf(output,"\tEND\t");    /* END directive to output file. */
  115.         fclose(output);
  116.         fclose(list);
  117. }
  118.